#pragma once

#include "Vectors.h"

class ServiceProvider;

class PlayerManager
{
public:
	PlayerManager(ServiceProvider* const i_sp);
	~PlayerManager();

	void				Clear();
	void				Initialize(const size_t i_startID = 0);

	Player*				GetNewPlayer();
	Player*				CreateNewPlayer(const bool i_isEmpty, const bool i_isBusy);

	void				IngagePlayer(Player* i_player);
	void				SellPlayer(Player* i_player);

	void				Update();
	void				EndSeasonUpdate();

	const PlayerVec&	GetBusyPlayers() const;
	const PlayerVec&	GetFreePlayers(const size_t i_minimumFreePlayers);
	const PlayerVec&	GetFreePlayers() const;
	const PlayerVec&	GetHofPlayers() const;
	Player*				GetPlayerFromID(const size_t i_playerID);
	size_t				GetLastID() const;
	size_t				GetNewID();

private:
	static size_t NUMBER_OF_PLAYERS;
	static const unsigned int SLOT_PLAYERS;
	static const unsigned int NUM_HOF_PLAYERS;

	PlayerVec m_busyPlayers;
	PlayerVec m_freePlayers;
	PlayerVec m_hofPlayers;

	ServiceProvider* m_sp;

	PlayerManager(const PlayerManager&);
	PlayerManager& operator=(const PlayerManager&);

	void GenerateNewPlayerSlot();
	void ShrinkHofPlayers();
	void UpdateFreePlayers();
};

inline size_t PlayerManager::GetLastID() const
{
	return NUMBER_OF_PLAYERS;
}

inline size_t PlayerManager::GetNewID()
{
	return ++NUMBER_OF_PLAYERS;
}

inline const PlayerVec& PlayerManager::GetHofPlayers() const
{
	return m_hofPlayers;
}

inline const PlayerVec& PlayerManager::GetBusyPlayers() const
{
	return m_busyPlayers;
}

inline const PlayerVec& PlayerManager::GetFreePlayers() const
{
	return m_freePlayers;
}

inline const PlayerVec& PlayerManager::GetFreePlayers(const size_t i_minimumFreePlayers)
{
	while(m_freePlayers.size() < i_minimumFreePlayers)
		GenerateNewPlayerSlot();
	return m_freePlayers;
}
